//
//  KSYJDDetViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/28.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "KSYJDDetViewController.h"

@interface KSYJDDetViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labOrder;
@property (weak, nonatomic) IBOutlet UILabel *labDate;
@property (weak, nonatomic) IBOutlet UILabel *labName;
@property (weak, nonatomic) IBOutlet UILabel *labPhone;
@property (weak, nonatomic) IBOutlet UILabel *labPlace;
@property (weak, nonatomic) IBOutlet UIView *starView;
@property (weak, nonatomic) IBOutlet UILabel *labPJ;

@property (nonatomic,strong) NSDictionary *dic;

@end

@implementation KSYJDDetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"订单详情"];
    [self loadData];
    
}

- (void)loadUI{
    _labOrder.text = [_dic objectForKey:@"ordernumber"];
    NSString *date = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"addtime"] integerValue]];
    NSString *time = [self getNewDate:date];
    _labDate.text = time;
    _labName.text = [_dic objectForKey:@"person"];
    _labPhone.text = [_dic objectForKey:@"phone"];
    _labPlace.text = [_dic objectForKey:@"address"];
    
    NSDictionary *comment = [_dic objectForKey:@"comment"];
    if ([comment isKindOfClass:[NSDictionary class]]) {
        StarView *star = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 80, 16)];
        star.showStar = 0;
        [_starView addSubview:star];
        
        _labPJ.text = @"暂无用户评价";
    }else{
        StarView *star = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 80, 16)];
        NSString *count = [[_dic objectForKey:@"comment"] objectForKey:@"star"];
        NSInteger index = [count integerValue];
        star.showStar = index * 20.0;
        [_starView addSubview:star];
        
        _labPJ.text = [[_dic objectForKey:@"comment"] objectForKey:@"comment"];
    }
}

//开锁完成详情
- (void)loadData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_orderid forKey:@"id"];
    [parmas setObject:_merid forKey:@"merchantid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Ordermanage/lockorderdetails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"开锁完成详情res:%@",responseObject);
        //        _array = [[responseObject objectForKey:@"result"] objectForKey:@"delivery"];
        _dic = [responseObject objectForKey:@"result"];
        [self loadUI];
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
